home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / Metalworks / MetalworksFrame.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  6.2 KB  |  240 lines

  1. /*
  2.  * @(#)MetalworksFrame.java    1.10 98/08/26
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import java.awt.*;
  16. import java.io.*;
  17. import java.awt.event.*;
  18. import java.beans.*;
  19. import javax.swing.*;
  20. import javax.swing.border.*;
  21.  
  22. import javax.swing.plaf.metal.*;
  23.  
  24.  
  25. /**
  26.   * This is the main container frame for the Metalworks demo app
  27.   *
  28.   * @version 1.10 08/26/98
  29.   * @author Steve Wilson
  30.   */
  31. public class MetalworksFrame extends JFrame {
  32.  
  33.     JMenuBar menuBar;
  34.     JDesktopPane desktop;
  35.     JInternalFrame toolPalette;
  36.     JCheckBoxMenuItem showToolPaletteMenuItem;
  37.  
  38.     static final Integer DOCLAYER = new Integer(5);
  39.     static final Integer TOOLLAYER = new Integer(6);
  40.     static final Integer HELPLAYER = new Integer(7);
  41.  
  42.     static final String ABOUTMSG = "Metalworks \n \nAn application written to show off the Java Look & Feel. \n \nWritten by the JavaSoft Look & Feel Team \n  Michael Albers\n  Tom Santos\n  Jeff Shapiro\n  Steve Wilson";
  43.  
  44.  
  45.     public MetalworksFrame() {
  46.         super("Metalworks");
  47.         final int inset = 50;
  48.         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  49.     setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );
  50.     buildContent();
  51.     buildMenus();
  52.     this.addWindowListener(new WindowAdapter() {
  53.                            public void windowClosing(WindowEvent e) {
  54.                    quit();
  55.                    }});
  56.     UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane()));
  57.     }
  58.  
  59.     protected void buildMenus() {
  60.         menuBar = new JMenuBar();
  61.     menuBar.setOpaque(true);
  62.     JMenu file = buildFileMenu();
  63.     JMenu edit = buildEditMenu();
  64.     JMenu views = buildViewsMenu();
  65.     JMenu help = buildHelpMenu();
  66.  
  67.     // load a theme from a text file
  68.     MetalTheme myTheme = null;
  69.     try {
  70.         myTheme =  new PropertiesMetalTheme(new FileInputStream("MyTheme.theme"));
  71.     } catch (IOException e) {System.out.println(e);}
  72.  
  73.     // build an array of themes
  74.     MetalTheme[] themes = { new DefaultMetalTheme(),
  75.                 new GreenMetalTheme(),
  76.                 new AquaMetalTheme(),
  77.                 new KhakiMetalTheme(),
  78.                 new DemoMetalTheme(),
  79.                 new ContrastMetalTheme(),
  80.                 new BigContrastMetalTheme(),
  81.                             myTheme };
  82.  
  83.     // put the themes in a menu
  84.     JMenu themeMenu = new MetalThemeMenu("Theme", themes);
  85.  
  86.     menuBar.add(file);
  87.     menuBar.add(edit);
  88.     menuBar.add(views);
  89.     menuBar.add(themeMenu);
  90.     menuBar.add(help);
  91.     setJMenuBar(menuBar);    
  92.     }
  93.  
  94.     protected JMenu buildFileMenu() {
  95.     JMenu file = new JMenu("File");
  96.     JMenuItem newWin = new JMenuItem("New");
  97.     JMenuItem open = new JMenuItem("Open");
  98.     JMenuItem quit = new JMenuItem("Quit");
  99.  
  100.     newWin.addActionListener(new ActionListener() {
  101.                            public void actionPerformed(ActionEvent e) {
  102.                    newDocument();
  103.                    }});
  104.  
  105.     open.addActionListener(new ActionListener() {
  106.                            public void actionPerformed(ActionEvent e) {
  107.                    openDocument();
  108.                    }});
  109.  
  110.     quit.addActionListener(new ActionListener() {
  111.                            public void actionPerformed(ActionEvent e) {
  112.                    quit();
  113.                    }});
  114.  
  115.     file.add(newWin);
  116.     file.add(open);
  117.     file.addSeparator();
  118.     file.add(quit);
  119.     return file;
  120.     }
  121.  
  122.     protected JMenu buildEditMenu() {
  123.     JMenu edit = new JMenu("Edit");
  124.     JMenuItem undo = new JMenuItem("Undo");
  125.     JMenuItem copy = new JMenuItem("Copy");
  126.     JMenuItem cut = new JMenuItem("Cut");
  127.     JMenuItem paste = new JMenuItem("Paste");
  128.     JMenuItem prefs = new JMenuItem("Preferences...");
  129.  
  130.     undo.setEnabled(false);
  131.     copy.setEnabled(false);
  132.     cut.setEnabled(false);
  133.     paste.setEnabled(false);
  134.  
  135.     prefs.addActionListener(new ActionListener() {
  136.                            public void actionPerformed(ActionEvent e) {
  137.                    openPrefsWindow();
  138.                    }});
  139.  
  140.     edit.add(undo);
  141.     edit.addSeparator();
  142.     edit.add(cut);
  143.     edit.add(copy);
  144.     edit.add(paste);
  145.     edit.addSeparator();
  146.     edit.add(prefs);
  147.     return edit;
  148.     }
  149.  
  150.     protected JMenu buildViewsMenu() {
  151.     JMenu views = new JMenu("Views");
  152.  
  153.     JMenuItem inBox = new JMenuItem("Open In-Box");
  154.     JMenuItem outBox = new JMenuItem("Open Out-Box");
  155.     outBox.setEnabled(false);
  156.  
  157.     inBox.addActionListener(new ActionListener() {
  158.                            public void actionPerformed(ActionEvent e) {
  159.                    openInBox();
  160.                    }});
  161.  
  162.     views.add(inBox);
  163.     views.add(outBox);
  164.     return views;
  165.     }
  166.  
  167.     protected JMenu buildHelpMenu() {
  168.     JMenu help = new JMenu("Help");
  169.         JMenuItem about = new JMenuItem("About Metalworks...");
  170.     JMenuItem openHelp = new JMenuItem("Open Help Window");
  171.  
  172.     about.addActionListener(new ActionListener() {
  173.         public void actionPerformed(ActionEvent e) {
  174.             showAboutBox();
  175.         }
  176.     });
  177.  
  178.     openHelp.addActionListener(new ActionListener() {
  179.                            public void actionPerformed(ActionEvent e) {
  180.                    openHelpWindow();
  181.                    }});
  182.  
  183.     help.add(about);
  184.     help.add(openHelp);
  185.  
  186.     return help;
  187.     }
  188.  
  189.     protected void buildContent() {
  190.         desktop = new JDesktopPane();
  191.         getContentPane().add(desktop);
  192.     }
  193.  
  194.     public void quit() {
  195.         System.exit(0);
  196.     }
  197.  
  198.     public void newDocument() {
  199.     JInternalFrame doc = new MetalworksDocumentFrame();
  200.     desktop.add(doc, DOCLAYER);
  201.     try { 
  202.         doc.setSelected(true); 
  203.     } catch (java.beans.PropertyVetoException e2) {}
  204.     }
  205.  
  206.     public void openDocument() {
  207.         JFileChooser chooser = new JFileChooser();
  208.     chooser.showOpenDialog(this);
  209.     }
  210.  
  211.     public void openHelpWindow() {
  212.     JInternalFrame help = new MetalworksHelp();
  213.     desktop.add(help, HELPLAYER);
  214.     try { 
  215.         help.setSelected(true); 
  216.     } catch (java.beans.PropertyVetoException e2) {}
  217.     }
  218.  
  219.     public void showAboutBox() {
  220.         JOptionPane.showMessageDialog(this, ABOUTMSG);
  221.     }
  222.  
  223.     public void openPrefsWindow() {
  224.         MetalworksPrefs dialog = new MetalworksPrefs(this);
  225.     dialog.show();
  226.  
  227.     }
  228.  
  229.     public void openInBox() {
  230.     JInternalFrame doc = new MetalworksInBox();
  231.     desktop.add(doc, DOCLAYER);
  232.     try { 
  233.         doc.setSelected(true); 
  234.     } catch (java.beans.PropertyVetoException e2) {}
  235.     }
  236.  
  237. }
  238.  
  239.  
  240.